<include file="Public/min-header"/>
<style>
    ul.group-list {
        width: 96%;min-width: 1000px; margin: auto 5px;list-style: disc outside none;
    }
    ul.group-list li {
        white-space: nowrap;float: left;
        width: 150px; height: 25px;
        padding: 3px 5px;list-style-type: none;
        list-style-position: outside;border: 0px;margin: 0px;
    }
</style>

<script type="text/javascript">
    window.UEDITOR_Admin_URL = "__ROOT__/Public/plugins/Ueditor/";
    var URL_upload = "{$URL_upload}";
    var URL_fileUp = "{$URL_fileUp}";
    var URL_scrawlUp = "{$URL_scrawlUp}";
    var URL_getRemoteImage = "{$URL_getRemoteImage}";
    var URL_imageManager = "{$URL_imageManager}";
    var URL_imageUp = "{$URL_imageUp}";
    var URL_getMovie = "{$URL_getMovie}";
    var URL_home = "{$URL_home}";</script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
    var editor;
    $(function () {
        //具体参数配置在  editor_config.js  中
        var options = {
            zIndex: 999,
            initialFrameWidth: "95%", //初化宽度
            initialFrameHeight: 400, //初化高度
            focus: false, //初始化时，是否让编辑器获得焦点true或false
            maximumWords: 99999,
            removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign', //允许的最大字符数 'fullscreen',
            pasteplain: false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
            autoHeightEnabled: true,
            /*   autotypeset: {
             mergeEmptyline: true, //合并空行
             removeClass: true, //去掉冗余的class
             removeEmptyline: false, //去掉空行
             textAlign: "left", //段落的排版方式，可以是 left,right,center,justify 去掉这个属性表示不执行排版
             imageBlockLine: 'center', //图片的浮动方式，独占一行剧中,左右浮动，默认: center,left,right,none 去掉这个属性表示不执行排版
             pasteFilter: false, //根据规则过滤没事粘贴进来的内容
             clearFontSize: false, //去掉所有的内嵌字号，使用编辑器默认的字号
             clearFontFamily: false, //去掉所有的内嵌字体，使用编辑器默认的字体
             removeEmptyNode: false, // 去掉空节点
             //可以去掉的标签
             removeTagNames: {
             "font": 1
             },
             indent: false, // 行首缩进
             indentValue: '0em' //行首缩进的大小
             },*/
            toolbars: [
                ['fullscreen', 'source', '|', 'undo', 'redo',
                    '|', 'bold', 'italic', 'underline', 'fontborder',
                    'strikethrough', 'superscript', 'subscript',
                    'removeformat', 'formatmatch', 'autotypeset',
                    'blockquote', 'pasteplain', '|', 'forecolor',
                    'backcolor', 'insertorderedlist',
                    'insertunorderedlist', 'selectall', 'cleardoc', '|',
                    'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                    'customstyle', 'paragraph', 'fontfamily', 'fontsize',
                    '|', 'directionalityltr', 'directionalityrtl',
                    'indent', '|', 'justifyleft', 'justifycenter',
                    'justifyright', 'justifyjustify', '|', 'touppercase',
                    'tolowercase', '|', 'link', 'unlink', 'anchor', '|',
                    'imagenone', 'imageleft', 'imageright', 'imagecenter',
                    '|', 'insertimage', 'emotion', 'insertvideo',
                    'attachment', 'map', 'gmap', 'insertframe',
                    'insertcode', 'webapp', 'pagebreak', 'template',
                    'background', '|', 'horizontal', 'date', 'time',
                    'spechars', 'wordimage', '|',
                    'inserttable', 'deletetable',
                    'insertparagraphbeforetable', 'insertrow', 'deleterow',
                    'insertcol', 'deletecol', 'mergecells', 'mergeright',
                    'mergedown', 'splittocells', 'splittorows',
                    'splittocols', '|', 'print', 'preview', 'searchreplace'
                ]
            ]
        };
        editor = new UE.ui.Editor(options);
        editor.render("goods_content"); //  指定 textarea 的  id 为 goods_content

    });</script>

<div class="wrapper">
    <include file="Public/breadcrumb" />
    <section class="content">
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i>商品详情</h3>
                </div>
                <div class="panel-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_tongyong" data-toggle="tab">通用信息</a></li>
                        <!--                        <li><a href="#tab_goods_desc" data-toggle="tab">描述信息</a></li>-->
                        <li><a href="#tab_goods_img" data-toggle="tab">商品相册</a></li>
                        <li><a href="#tab_goods_spec" data-toggle="tab">商品规格</a></li>
                        <li><a href="#tab_goods_to_attr" data-toggle="tab">商品属性</a></li>
                        <li><a href="#tab_goods_shipping" data-toggle="tab">商品物流</a></li>
                    </ul>
                    <form method="post" id="addEditGoodsForm">

                        <div class="tab-content">
                            <div class="tab-pane active" id="tab_tongyong">
                                <table class="table table-bordered">
                                    <tbody>
                                        <tr>
                                            <td class = "text-right">商品名称:</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.goods_name}" name="goods_name" class="form-control" style="width:550px;" />
                                                <span id="err_goods_name" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">商品简介:</td>
                                            <td>
                                                <textarea rows="3" cols="80" name="goods_remark" class = "form-control">{$goodsInfo.goods_remark}</textarea>
                                                <span id="err_goods_remark" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">商品货号</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.goods_sn}" name="goods_sn" class="form-control" style="width:350px;" />
                                                <span id="err_goods_sn" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">SPU</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.spu}" name="spu" class="form-control" style="width:350px;" />
                                                <span id="err_goods_spu" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">SKU</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.sku}" name="sku" class="form-control" style="width:350px;" />
                                                <span id="err_goods_sku" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">商品分类:</td>
                                            <td>
                                                <div class="col-xs-3" style = "width:250px">
                                                    <select name="cat_id" id="cat_id" onchange="getCategory(this.value, 'cat_id_2', '0');" class="form-control" style="width:250px;margin-left:-15px;">
                                                        <option value="0">请选择商品分类</option>
                                                        <foreach name="cat_list" item="v" key="k">
                                                            <option value="{$v['id']}" <if condition="$v['id'] eq $level_cat['1']">selected="selected"</if> > {$v['name']}
                                                            </option>
                                                        </foreach>
                                                    </select>
                                                </div>
                                                <div class="col-xs-3" style = "width:250px">
                                                    <select name="cat_id_2" id="cat_id_2" onchange="getCategory(this.value, 'cat_id_3', '0');" class="form-control" style="width:250px;margin-left:-15px;">
                                                        <option value="0">请选择商品分类</option>
                                                    </select>
                                                </div>
                                                <div class="col-xs-3" style = "width:250px">
                                                    <select name="cat_id_3" id="cat_id_3" class="form-control" style="width:250px;margin-left:-15px;">
                                                        <option value="0">请选择商品分类</option>
                                                    </select>
                                                </div>
                                                <span id="err_cat_id" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">扩展分类:</td>
                                            <td>
                                                <div class="col-xs-3" style = "width:250px">
                                                    <select name="extend_cat_id" id="extend_cat_id" onchange="getCategory(this.value, 'extend_cat_id_2', '0');" class="form-control" style="width:250px;margin-left:-15px;">
                                                        <option value="0">请选择商品分类</option>
                                                        <foreach name="cat_list" item="v" key="k">
                                                            <option value="{$v['id']}" <if condition="$v['id'] eq $level_cat2['1']">selected="selected"</if> > {$v['name']}
                                                            </option>
                                                        </foreach>
                                                    </select>
                                                </div>
                                                <div class="col-xs-3" style = "width:250px">
                                                    <select name="extend_cat_id_2" id="extend_cat_id_2" onchange="getCategory(this.value, 'extend_cat_id_3', '0');" class="form-control" style="width:250px;margin-left:-15px;">
                                                        <option value="0">请选择商品分类</option>
                                                    </select>
                                                </div>
                                                <div class="col-xs-3" style = "width:250px">
                                                    <select name="extend_cat_id_3" id="extend_cat_id_3" class="form-control" style="width:250px;margin-left:-15px;">
                                                        <option value="0">请选择商品分类</option>
                                                    </select>
                                                </div>
                                                <span id="err_cat_id" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <!--
                                                                        <tr>
                                                                            <td>商品分类:</td>
                                                                            <td>
                                                                              <select name="cat_id" id="cat_id" class="form-control" style="width:250px;">
                                                                                <option value="">所有分类</option>
                                                                                     <foreach name="cat_list" item="v" key="k" >                                                                                          
                                                                                       <option value="{$v['id']}" <if condition="$v['id'] eq $goodsInfo['cat_id'] ">selected="selected"</if> >
                                                                                                <?php echo  str_pad('',($v[level] * 5),'-',STR_PAD_LEFT);  ?> {$v['name']}
                                                                                       </option>
                                                                                     </foreach>
                                                                              </select>                                    
                                                                            </td>
                                                                        </tr>
                                        -->
                                        <tr>
                                            <td class = "text-right">商品品牌:</td>
                                            <td>
                                                <select name="brand_id" id="brand_id" class="form-control" style="width:250px;">
                                                    <option value="">所有品牌</option>
                                                    <foreach name="brandList" item="v" key="k">
                                                        <option value="{$v['id']}" <if condition="$v['id'] eq $goodsInfo['brand_id'] ">selected="selected"</if>> {$v['name']}
                                                        </option>
                                                    </foreach>
                                                </select>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">本店售价:</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.shop_price}" name="shop_price" class="form-control" style="width:150px;" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" />
                                                <span id="err_shop_price" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">市场价:</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.market_price}" name="market_price" class="form-control" style="width:150px;" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" />
                                                <span id="err_market_price" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">成本价:</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.cost_price}" name="cost_price" class="form-control" style="width:150px;" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" />
                                                <span id="err_cost_price" style="color:#F00; display:none"></span>
                                            </td>
                                        </tr>
<!--                                        <tr>
                                            <td>佣金:</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.commission}" name="commission" class="form-control" style="width:150px;" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" /> 用于分销的分成金额
                                            </td>
                                        </tr>-->
                                        <tr>
                                            <td class = "text-right">上传商品图片:</td>
                                            <td>
                                                <input type="button" value="上传图片" onclick="GetUploadify(1, '', 'goods', 'call_back');" />
                                                <input type="text" class="input-sm" name="original_img" id="original_img" value="{$goodsInfo.original_img}" />
                                    <if condition="$goodsInfo['original_img'] neq null">
                                        &nbsp;&nbsp;
                                        <a target="_blank" href="{$goodsInfo.original_img}" id="original_img2">
                                            <img width="25" height="25" src="/Public/images/image_icon.jpg">
                                        </a>
                                    </if>
                                    <span id="err_original_img" style="color:#F00; display:none;"></span>
                                    </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">商品重量:</td>
                                        <td>
                                            <input type="text" class="form-control" style="width:150px;" value="{$goodsInfo.weight|default=0}" name="weight" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" /> &nbsp;克 (以克为单位) 0为免运费
                                            <span id="err_weight" style="color:#F00; display:none;"></span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">是否包邮:</td>
                                        <td>
                                            是:
                                    <input type="radio" <if condition="$goodsInfo[is_free_shipping] eq 1">checked="checked"</if> value="1" name="is_free_shipping" /> 否:
                                    <input type="radio" <if condition="$goodsInfo[is_free_shipping] eq 0">checked="checked"</if> value="0" name="is_free_shipping" />
                                    </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">库存数量:</td>
                                        <td>
                                    <if condition="$goodsInfo[goods_id] gt 0">
                                        <input type="text" value="{$goodsInfo.store_count}" class="form-control" style="width:150px;" name="store_count" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" />
                                        <else />
                                        <input type="text" value="{$xiarikui_config[basic_default_storage]}" class="form-control" style="width:150px;" name="store_count" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" />
                                    </if>
                                    <span id="err_store_count" style="color:#F00; display:none;"></span>
                                    </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">赠送积分:</td>
                                        <td>
                                            <input type="text" class="form-control" style="width:150px;" value="{$goodsInfo.give_integral}" name="give_integral" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" />
                                            <span id="err_give_integral" style="color:#F00; display:none;"></span>
                                        </td>
                                    </tr>
                                    <!--
                                <tr>
                                    <td>设置:</td>
                                    <td>
                                        <input type="checkbox" checked="checked" value="{$goodsInfo.is_on_sale}" name="is_on_sale"/> 上架&nbsp;&nbsp;
                                        <input type="checkbox" checked="checked" value="{$goodsInfo.is_free_shipping}" name="is_free_shipping"/> 包邮&nbsp;&nbsp;
                                        <input type="checkbox" checked="checked" value="{$goodsInfo.is_recommend}" name="is_recommend"/>推荐&nbsp;&nbsp;
                                        <input type="checkbox" checked="checked" value="{$goodsInfo.is_new}" name="is_new"/>新品&nbsp;&nbsp;
                                    </td>
                                </tr>
                                    -->
                                    <tr>
                                        <td class = "text-right">商品关键词:</td>
                                        <td>
                                            <input type="text" class="form-control" style="width:550px;" value="{$goodsInfo.keywords}" name="keywords" />用空格分隔
                                            <span id="err_keywords" style="color:#F00; display:none;"></span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">商品详情描述:</td>
                                        <td width="85%">
                                            <textarea class="span12 ckeditor" id="goods_content" name="goods_content" title="">{$goodsInfo.goods_content}</textarea>
                                            <span id="err_goods_content" style="color:#F00; display:none;"></span>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>

                            <div class="tab-pane" id="tab_goods_img">
                                <table class="table table-bordered">
                                    <tbody>
                                        <tr>
                                            <td>
                                    <foreach name="goodsImg" item="vo" key="k">
                                        <div style="width:100px; text-align:center; margin: 5px; display:inline-block;" class="goods_xc">
                                            <input type="hidden" value="{$vo['image_url']}" name="goods_img[]">
                                            <a onclick="" href="{$vo['image_url']}" target="_blank"><img width="100" height="100" src="{$vo['image_url']}"></a>
                                            <br>
                                            <a href="javascript:;" onclick="ClearPicArr2(this, '{$vo['image_url']}')">删除</a>
                                        </div>
                                    </foreach>
                                    <div class="goods_xc" style="width:100px; text-align:center; margin: 5px; display:inline-block;">
                                        <input type="hidden" name="goods_img[]" value="" />
                                        <a href="javascript:;" onclick="GetUploadify(10, '', 'goods', 'call_back2');"><img src="/Public/images/add-button.jpg" width="100" height="100" /></a>
                                        <br/>
                                        <a href="javascript:;">&nbsp;&nbsp;</a>
                                    </div>
                                    </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>

                            <div class="tab-pane" id="tab_goods_spec">
                                <table class="table table-bordered" id="goods_spec_table">
                                    <tr>
                                        <td class = "text-right">商品类型:</td>
                                        <td>
                                            <select name="spec_type" id="spec_type" class="form-control" style="width:250px;">
                                                <option value="0">选择商品类型</option>
                                                <foreach name="goodsType" item="vo" key="k">
                                                    <option value="{$vo.id}" <if condition="$goodsInfo[spec_type] eq $vo[id]"> selected="selected" </if> >{$vo.name}</option>
                                                </foreach>
                                            </select>
                                        </td>
                                    </tr>
                                </table>
                                <div id="ajax_spec_data">
                                </div>
                            </div>

                            <div class="tab-pane" id="tab_goods_to_attr">
                                <table class="table table-bordered" id="goods_attr_table">
                                    <tr>
                                        <td class = "text-right">商品属性:</td>
                                        <td>
                                            <select name="goods_type" id="goods_type" class="form-control" style="width:250px;">
                                                <option value="0">选择商品属性</option>
                                                <foreach name="goodsType" item="vo" key="k">
                                                    <option value="{$vo.id}" <if condition="$goodsInfo[goods_type] eq $vo[id]"> selected="selected" </if> >{$vo.name}</option>
                                                </foreach>
                                            </select>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div class="tab-pane" id="tab_goods_shipping">
                                <h4><b>物流配送：</b><input type="checkbox" onclick="choosebox(this)">全选</h4>
                                <table class="table table-bordered table-striped dataTable" id="goods_shipping_table">
                                    <foreach name="pluginShipping" item="shipping" key="kk">
                                        <tr>
                                            <td class="title left" style="padding-right:50px;">
                                                <b>{$shipping[name]}：</b>
                                                <label class="right"><input type="checkbox" value="1" checked cka="mod-{$kk}">全选</label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <ul class="group-list" style = "margin-left:28px">
                                                    <foreach name="shipping_area" item="vv">
                                                        <if condition="$vv[shipping_code] eq $shipping[code]">
                                                            <li><label><input type="checkbox" name="shipping_area_ids[]" value="{$vv.shipping_area_id}" <if condition="in_array($vv['shipping_area_id'],$goods_shipping_area_ids)">checked='checked'</if> ck="mod-{$kk}">{$vv.shipping_area_name}</label></li>
                                                        </if>
                                                    </foreach>
                                                    <div class="clear-both"></div>
                                                </ul>
                                            </td>
                                        </tr>
                                    </foreach>
                                </table>
                            </div>
                        </div>
                        <div class="pull-right">
                            <input type="hidden" name="goods_id" value="{$goodsInfo.goods_id}">
                            <button class="btn btn-primary" onclick="ajax_submit_form('addEditGoodsForm', '{:U(\'Goods/addEditGoods?is_ajax=1\',array(\'p\'=>$_GET[p]))}');" title="" data-toggle="tooltip" type="button" data-original-title="保存">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
</div>
<script>
    $(document).ready(function(){
        $(":checkbox[cka]").click(function(){
            var $cks = $(":checkbox[ck='"+$(this).attr("cka")+"']");
            if($(this).is(':checked')){
                $cks.each(function(){$(this).prop("checked",true);});
            }else{
                $cks.each(function(){$(this).removeAttr('checked');});
            }
        });
    });

    function choosebox(o){
        var vt = $(o).is(':checked');
        if(vt){
            $('input[type=checkbox]').prop('checked',vt);
        }else{
            $('input[type=checkbox]').removeAttr('checked');
        }
    }
    /*
     * 以下是图片上传方法
     */
// 上传商品图片成功回调函数
    function call_back(fileurl_tmp) {
        $("#original_img").val(fileurl_tmp);
        $("#original_img2").attr('href', fileurl_tmp);
    }

// 上传商品相册回调函数
    function call_back2(paths) {

        var last_div = $(".goods_xc:last").prop("outerHTML");
        for (i = 0; i < paths.length; i++) {
            $(".goods_xc:eq(0)").before(last_div); // 插入一个 新图片
            $(".goods_xc:eq(0)").find('a:eq(0)').attr('href', paths[i]).attr('onclick', '').attr('target', "_blank"); // 修改他的链接地址
            $(".goods_xc:eq(0)").find('img').attr('src', paths[i]); // 修改他的图片路径
            $(".goods_xc:eq(0)").find('a:eq(1)').attr('onclick', "ClearPicArr2(this,'" + paths[i] + "')").text('删除');
            $(".goods_xc:eq(0)").find('input').val(paths[i]); // 设置隐藏域 要提交的值
        }
    }
    /*
     * 上传之后删除组图input     
     * @access   public
     * @val      string  删除的图片input
     */
    function ClearPicArr2(obj, path) {
        $.ajax({
            type: 'GET',
            url: "{:U('Admin/Uploadify/delupload')}",
            data: {
                action: "del",
                filename: path
            },
            success: function () {
                $(obj).parent().remove(); // 删除完服务器的, 再删除 html上的图片               
            }
        });
        // 删除数据库记录
        $.ajax({
            type: 'GET',
            url: "{:U('Admin/Goods/delGoodsImg')}",
            data: {
                filename: path
            },
            success: function () {
                //       
            }
        });
    }



    /** 以下 商品属性相关 js*/
    $(document).ready(function () {

        // 商品类型切换时 ajax 调用  返回不同的属性输入框
        $("#goods_type").change(function () {
            var goods_id = $("input[name='goods_id']").val();
            var type_id = $(this).val();
            $.ajax({
                type: 'GET',
                data: {
                    goods_id: goods_id,
                    type_id: type_id
                },
                url: "/index.php/admin/Goods/ajaxGetAttrInput",
                success: function (data) {
                    $("#goods_attr_table tr:gt(0)").remove()
                    $("#goods_attr_table").append(data);
                }
            });
        });
        // 触发商品类型
        $("#goods_type").trigger('change');
    });
// 属性输入框的加减事件
    function addAttr(a) {
        var attr = $(a).parent().parent().prop("outerHTML");
        attr = attr.replace('addAttr', 'delAttr').replace('+', '-');
        $(a).parent().parent().after(attr);
    }
// 属性输入框的加减事件
    function delAttr(a) {
        $(a).parent().parent().remove();
    }


    /** 以下 商品规格相关 js*/
    $(document).ready(function () {

        // 商品类型切换时 ajax 调用  返回不同的属性输入框
        $("#spec_type").change(function () {
            var goods_id = '{$goodsInfo.goods_id}';
            var spec_type = $(this).val();
            $.ajax({
                type: 'GET',
                data: {
                    goods_id: goods_id,
                    spec_type: spec_type
                },
                url: "{:U('admin/Goods/ajaxGetSpecSelect')}",
                success: function (data) {
                    $("#ajax_spec_data").html('');
                    $("#ajax_spec_data").append(data);
                    //alert('132');
                    ajaxGetSpecInput(); // 触发完  马上处罚 规格输入框
                }
            });
        });
        // 触发商品规格
        $("#spec_type").trigger('change');
    });
    /** 以下是编辑时默认选中某个商品分类*/
    $(document).ready(function () {

        '<if condition = "$level_cat[2] gt 0" >';
        // 商品分类第二个下拉菜单
        getCategory('{$level_cat[1]}', 'cat_id_2', '{$level_cat[2]}');
        '</if> ';
        '<if condition = "$level_cat[3] gt 0" >';
        // 商品分类第二个下拉菜单
        getCategory('{$level_cat[2]}', 'cat_id_3', '{$level_cat[3]}');
        '</if>';
        //  扩展分类
        '<if condition = "$level_cat2[2] gt 0" >';
        // 商品分类第二个下拉菜单
        getCategory('{$level_cat2[1]}', 'extend_cat_id_2', '{$level_cat2[2]}');
        '</if>';
        '<if condition = "$level_cat2[3] gt 0" >';
        // 商品分类第二个下拉菜单
        getCategory('{$level_cat2[2]}', 'extend_cat_id_3', '{$level_cat2[3]}');
        '</if>';
    });
</script>
</body>

</html>
